package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.MessageInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * Created by Administrater on 2015/12/8.
 */
public class SysMsgDetailTask extends CouponHttpBaseTask {
    private String mId ;
    public SysMsgDetailTask(String msgid){
        super(TaskType.SYSMSG_DETAIL_TASK);
        mId = msgid;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject respJson = response.getBody();
        MessageInfo info = null;
        if(respJson != null){
            info = JSON.parseObject(respJson.getString("data"), MessageInfo.class);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS,info);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if(mPhase == TASK_PHASE_INIT){
            CouponHttpRequest request = new CouponHttpRequest(RequestType.SYSMSG_DETAIL_REQUEST);
            JSONObject json = new JSONObject();
            json.put("msgId", mId);
            request.setData(json.toString());
            request.setApiNo(ApiNo.SYSMSG_DETAIL);
            addRequest(request);
        }
    }
}
